//
//  NYExamineTestView.m
//  NiuWaJiaoYu
//
//  Created by 袁航 on 2018/1/9.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYExamineTestView.h"
#import "NYAirlineViewController.h"
#import "NYExamineTestTimeHeaderView.h"
#import "NYExamineTestTimeFooterView.h"
@interface NYExamineTestView ()
@property(nonatomic, strong) NYExamineTestTimeHeaderView *headerView;
@property(nonatomic, strong) NYExamineTestTimeFooterView *footerView;
@end
@implementation NYExamineTestView
- (void)setTestListModel:(NYExamineTestListModel *)testListModel
{
        _testListModel = testListModel;
        self.headerView.testListModel = testListModel;
        self.footerView.testListModel = testListModel;
}
- (void)setStatus:(NYExamineRequestStatus)status {
        _status = status;
        self.footerView.status = _status;
}
- (NSString *)usedTime
{
        NSString *usedTime = [self.headerView.timerLabel.text substringWithRange:self.headerView.timerLabel.textRange];
        return usedTime;
}
- (void)setupTableView
{
        self.tableView.allowsMultipleSelection = YES;
        self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
        [self addSubview:self.headerView];
        [self addSubview:self.footerView];
        
        
        self.tableView.backgroundColor = UIColorForBackground;
        self.backgroundColor = UIColorForBackground;
        [self.headerView mas_remakeConstraints:^(MASConstraintMaker *make) {
                if (@available(iOS 11.0,*))
                {
                        make.top.equalTo(self.mas_safeAreaLayoutGuideTop);
                        make.left.equalTo(self.mas_safeAreaLayoutGuideLeft);
                        make.right.equalTo(self.mas_safeAreaLayoutGuideRight);
                }
                else
                {
                        make.top.equalTo(self.controller.mas_topLayoutGuideBottom);
                        make.left.right.equalTo(self);
                }
                make.height.mas_equalTo(__WGHeight(41));
        }];
        [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.headerView.mas_bottom);
                make.left.right.equalTo(self.headerView);
        }];
        [self.footerView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.right.equalTo(self.headerView);
                make.top.equalTo(self.tableView.mas_bottom);
                if (@available(iOS 11.0,*))
                {
                        make.bottom.equalTo(self.mas_safeAreaLayoutGuideBottom);
                }
                else
                {
                        make.bottom.equalTo(self.controller.mas_bottomLayoutGuideTop);
                }
                make.height.mas_equalTo(__WGHeight(56));
        }];
        @weakify(self);
        [self.footerView.msgBtn jk_addActionHandler:^(NSInteger tag) {
                @strongify(self);
                if (self.actionBlock) {
                        self.actionBlock(NYExamineTestViewActionTypeJumpToMsg);
                }
        }];
        [self.footerView.submitBtn jk_addActionHandler:^(NSInteger tag) {
                @strongify(self);
                if (self.actionBlock) {
                        self.actionBlock(NYExamineTestViewActionTypeSubmit);
                }
        }];
}

- (NYExamineTestTimeHeaderView *)headerView
{
        if ( _headerView == nil )
        {
                _headerView = [[NYExamineTestTimeHeaderView alloc] init];
        }
        return _headerView;
}
- (NYExamineTestTimeFooterView *)footerView
{
        if ( _footerView == nil )
        {
                _footerView = [[NYExamineTestTimeFooterView alloc] init];
        }
        return _footerView;
}
@end
